package Demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-06-04
 * Time: 14:29
 */
class Demo<T extends Number>{
    private Object[] array = new Object[10];

    public T getArray(int pos) {
        return (T)array[pos];
    }

    public void setArray(int pos,T array) {
        this.array[pos] = array;
    }
}
public class Test {
    public static void main(String[] args) {
        Integer value = 0;
        Demo<Integer> integerDemo = new Demo<Integer>();
        integerDemo.setArray(3,3);
    }

    public static void main2(String[] args) {
        Demo<Integer> demo = new Demo<Integer>();
//        demo.setArray(0,"djd");//编译器会自动进行类型检查
        demo.setArray(0,1);
        System.out.println(demo.getArray(0));//编译器会自动进行类型转换
    }
    public static void main1(String[] args) {
        Demo demo = new Demo();
        demo.setArray(0,5);
//        demo.setArray(1,"hello");
        int value = (int)demo.getArray(0);
//        String str = (String)demo.getArray(1);
        System.out.println(value);
        System.out.println();
//        Integer a = 1;
//        String str = (Integer)a;
    }
}
